//
//  LRXRandomString.m
//  路人侠
//
//  Created by zhangxulong on 5/4/16.
//  Copyright © 2016 zhangxulong. All rights reserved.
//

#import "LRXRandomString.h"

@implementation LRXRandomString
+ (NSString *)RandomStringWithLenght:(NSInteger)length withModel:(RandomStringModel)stringModel
{
    NSString * randomStr = @"";
    NSMutableArray * resource = [NSMutableArray array];
    
    for (int i = 0; i <= 9; i++) {
        NSString * str = [NSString stringWithFormat:@"%d",i];
        [resource addObject:str];
    }
    for (int i = 'a'; i <= 'z'; i++) {
        NSString * str = [NSString stringWithFormat:@"%c",i];
        [resource addObject:str];
    }
    
    
    if (stringModel == digitalCharacterMix) {
        while (length--) {
            
            randomStr = [randomStr stringByAppendingString:resource[arc4random() % resource.count]];
        }
    }
    else if(stringModel == Alphanumeric)
    {
        while (length--) {
            randomStr = [randomStr stringByAppendingString:resource[arc4random() % 10]];
        }
    }
    else if(stringModel == CharacterLetters)
    {
        while (length--) {
            randomStr = [randomStr stringByAppendingString:resource[(arc4random() % resource.count) + 10]];
        }
    }
    return randomStr;
}
@end
